package com.homework.service.impl;

import com.homework.dao.UserDao;
import com.homework.service.NameService;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class NameServiceImpl implements NameService {
    private UserDao dao;
    private SqlSession ss;

    public NameServiceImpl() {
        SqlSessionFactoryBuilder ssfb = new SqlSessionFactoryBuilder();
        InputStream in = this.getClass().getClassLoader().getResourceAsStream("mybatis/RollCall-mybatis-config.xml");
        SqlSessionFactory ssf = ssfb.build(in);
        ss = ssf.openSession();
        dao = ss.getMapper(UserDao.class);
    }

    @Override
    public List<String> findName() {
        List<String> allName = dao.findAllName();
        ss.commit();
        return allName;
    }
}
